<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>01_Canvas-绘制矩形</title>
  <style>
    body{
      margin: 0;
      padding: 0;
      background-image: url(../../images/grid.png);
    }
    canvas{
      background-color: rgba(255, 0, 0, 0.1);
    }
  </style>
</head>
<body>

  <canvas id="tutorial" width="300" height="300">
    你的浏览器不兼容Canvas,请升级您的浏览器!
  </canvas>

  <script>
    window.onload = function() {
      let canvasEl = document.getElementById('tutorial')
      if(!canvasEl.getContext) {
        return
      }
      let ctx = canvasEl.getContext('2d')
      // 1.绘制了一个填充的矩形
      ctx.fillStyle = 'rgba(0, 0, 255, 0.5)' // 设置填充颜色
      ctx.fillRect(0, 0, 100, 50) 

      // 2.绘制一个边框的矩形
      ctx.strokeRect(100, 100, 100, 50) // 设置边框颜色

      // 3. 清除指定区域, 也就是将指定区域变为透明
      ctx.clearRect(0, 0, 10, 50)
    }

  </script>
  
</body>
</html>